﻿using Abp.Collections.Extensions;
using Abp.EntityFramework;
using JHT.SimpleTaskSystem.IRepository;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JHT.SimpleTaskSystem.EntityFramework.Repositories
{
    public class SimpleTaskRepository : SimpleTaskSystemRepositoryBase<SimpleTask, long>, ITaskRepository
    {
        public SimpleTaskRepository(IDbContextProvider<SimpleTaskSystemDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public List<SimpleTask> GetAllWithPeople(int? assignedPersonId, TaskStateEnum? state)
        {
            var query = GetAll();
            query.WhereIf(assignedPersonId.HasValue, p => p.AssignedPersonId == assignedPersonId);
            query.WhereIf(state.HasValue, p => p.State == state);

            return
                query
                .OrderByDescending(p => p.CreationTime)
                .Include(p => p.AssignedPerson)//在Application层调用是需要引用System.Data.Entity
                .ToList();
        }
    }
}
